package org.example.struct.array;

/**
 * @author liyishan
 * @date 2024/9/9 13:43
 * @apiNote
 */

public class Test02379MinimumRecolors {
    public int minimumRecolors(String blocks, int k) {
        char[] chars = blocks.toCharArray();
        int min = blocks.length();
        int count = 0;
        for (int i = 0; i < k; i++) {
            if (chars[i] == 'W') {
                count++;
            }
        }
        min = Math.min(min, count);
        for (int i = k; i < blocks.length(); i++) {
            count = count - (chars[i - k] == 'W' ? 1 : 0) + (chars[i] == 'W' ? 1 : 0);
            min = Math.min(min, count);
        }
        return min;
    }
}
